package cn.afactory.tygz.model;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.List;

/**
 * Created with Android Studio.
 * Title:NearByUserInfo
 * Description:
 * Copyright:Copyright (c) 2015
 * Company:和平必胜、正义必胜、人民必胜
 * Author:炎黄子孙
 * Date:15/9/14
 * Time:上午10:01
 * Version 1.0
 */
public class NearByUserInfo implements Serializable {

    private static final long serialVersionUID = -7794201820930475492L;

    public String nickName;

    public String userIcon;

    public long userId;

    public int sex;

    public long birth;

    public String companyName;

    public String cityName;

    public double distance;

    /**
     * 反序列化函数，用于从json字符串反序列化本类型实例
     */
    public static NearByUserInfo deserialize(String json) throws JSONException {
        if (json != null && !json.isEmpty()) {
            return deserialize(new JSONObject(json));
        }
        return null;
    }

    /**
     * 反序列化函数，用于从json节点对象反序列化本类型实例
     */
    public static NearByUserInfo deserialize(JSONObject json) throws JSONException {
        if (json != null && json != JSONObject.NULL && json.length() > 0) {
            NearByUserInfo result = new NearByUserInfo();

            result.sex = json.optInt("sex");

            if (!json.isNull("nickName")) {
                result.nickName = json.optString("nickName", null);
            }

            if (!json.isNull("userIcon")) {
                result.userIcon = json.optString("userIcon", null);
            }

            if (!json.isNull("companyName")) {
                result.companyName = json.optString("companyName", null);
            }

            if (!json.isNull("cityName")) {
                result.cityName = json.optString("cityName", null);
            }

            result.distance = json.optDouble("distance");

            result.birth = json.optLong("birth");

            result.userId = json.optLong("userId");

            return result;
        }
        return null;
    }
}
